package logic

import (
	"context"
	"order/internal/model"

	"order/internal/svc"
	"order/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderUpdateLogic {
	return &OrderUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderUpdateLogic) OrderUpdate(in *order.OrderUpdateRequest) (*order.OrderUpdateResponse, error) {
	orderModel := model.NewOrderModel(l.ctx, l.svcCtx)
	orderCreated, err := orderModel.OrderStatusTake(in.No)
	if err != nil {
		return nil, err
	}

	return &order.OrderUpdateResponse{Upd: &order.OrderInfo{
		OrderNo:    in.No,
		UserId:     int64(orderCreated.UserId),
		GoodsId:    int64(orderCreated.GoodsId),
		OrderNum:   int64(orderCreated.OrderNum),
		OrderPrice: float32(orderCreated.OrderPrice),
		CreatedAt:  orderCreated.OrderNo,
	}}, nil
}
